package com.btkjgc.utils;

import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;

public class JsonUtil {
	
	//jsonString to JsonObject
	public static String StringToJsonObject(String account){
		
		String[] result = null;
		String totalMiles = null;
		
		try
		{
			String jsonMessage = HttpPostUrlUtil.post("http://121.41.50.122:8080/ElectricChargeSystem/getCarInfo", "{\n" +
	                "\"userId\":\"123\",\n" +
	                "\"commandId\":\"1\",\n" +
	                "\"account\":\""+account+"\"\n" +
	                "}");
			//将字符串转换成jsonObject对象
			JSONObject myJsonObject = new JSONObject(jsonMessage);
			//获取对应的值
			System.out.println(jsonMessage);
			result = myJsonObject.getString("totalMiles").split("\\.");
			totalMiles = result[0];
			
		}catch(IOException e){
			e.printStackTrace();
		}catch (JSONException e){
			e.printStackTrace();
		}
		  
		System.out.println(totalMiles);
		return totalMiles;
	}
	
	public static void main(String[] args) {
		
		JsonUtil.StringToJsonObject("2017031015432100000004");
		
	}
	
}